package com.zhuang.chapter10.work05;

import java.util.Scanner;

public class StringMatch {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入两个字符串,用,分隔");
		String[] strings = sc.nextLine().split(",");
		String string1 = strings[0];
		String string2 = strings[1];
		if (match(string1, string2)) {
			System.out.println("匹配成功!");
		} else {
			System.out.println("匹配失败");
		}
	}

	public static boolean match(String string1, String string2) {
		char[] arr = string1.toCharArray();
		int n = string1.toCharArray().length;
		// 定义指针
		int point = 1;
		while (point <= string2.length()) {
			// 把第一个数拿到 准备赋值给尾部的值
			char last = arr[0];
			for (int i = 0; i < n - 1; i++) {
				arr[i] = arr[i + 1];
			}
			arr[n - 1] = last;
			point++;
			System.out.println(arr);
			if (String.valueOf(arr).equals(string2)) {
				return true;
			}
		}
		return false;
	}
}
